// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import axios from 'axios'
import vuex from 'vuex'
import store from "./store";
import http from './utils/http'

Vue.prototype.$http = http;
Vue.prototype.axios = axios;
Vue.config.productionTip = false

Vue.use(ElementUI);
Vue.use(vuex);


// 路由在跳转之前进行调用，sessionStorage在浏览器中保存状态
router.beforeEach((to,from,next)=>{
  let isLogin = sessionStorage.getItem("isLogin");

  if (to.path === '/logout'){
    sessionStorage.clear();
    next({path: '/login'});
    return;
  }
  else if (to.path === '/login'){
    if (isLogin ==='true'){
      next({path: '/main/userCenter'});
      return;
    }
  }
  else if(isLogin == null){
    next({path: '/login'});
    return;
  }
  next();
});



/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  store,
  components: { App },
  template: '<App/>',
  render: h => h(App)
})
